Skip to content

Document both shapes for device resident outputs - #23102

Merged
shoumikhin merged 1 commit into
pytorch:mainfrom
shoumikhin:cuda-doc-device-resident-outputs
Sep 24, 2026
Merged

shoumikhin merged 1 commit into
pytorch:mainfrom
shoumikhin:cuda-doc-device-resident-outputs

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

The CUDA page tells you to export device resident inputs and outputs with unplanned graph outputs.
A Python caller cannot follow that recipe.

An unplanned output means the program reserves no buffer, so the caller has to supply one before the
method runs. From C++ that is natural, since the caller makes a tensor on the device and hands over
its pointer. The Python bindings do it for the caller and they do it on the host, so a device
resident output is given host memory and the run fails.

The setting the page warns against is the one that works from Python. With
enable_non_cpu_memory_planning on, a planned output buffer is allocated on the device, and
skip_d2h_for_method_outputs means nothing copies it back, so the result stays on the device and
the caller receives a pointer to the runtime's own buffer. That buffer belongs to the method and is
reused by the next execution, which the page now says. It is also what the exporters in this
repository already do, for example examples/models/gemma4_31b/export.py.

The input half of the recipe was correct and is unchanged. The output half now describes two shapes:
planned when the caller cannot supply device memory, which is every Python caller today, and
unplanned when it can, which today means a C++ caller handing the runtime a device tensor through
Module::set_output.

Fixes #23101

Test plan: read against the example exporters in this repository, which use unplanned inputs and
planned outputs together with both copy skips. No code changed.

cc @mergennachin @nil-is-all @Gasoonjia @digantdesai

The CUDA page tells you to export device resident inputs and outputs with
unplanned graph outputs. A Python caller cannot follow that. An unplanned
output means the program reserves no buffer, so the caller has to supply one,
and the Python bindings supply host memory. A CUDA delegated method then fails
to run.

The setting the page warns against is the one that works from Python. With
non CPU memory planning on, a planned output buffer is allocated on the device,
and skipping the device to host copy means nothing brings it back, so the
result stays on the device and the caller receives a pointer to the runtime's
own buffer. That is also what the exporters in this repository already do.

The input half of the recipe was correct and is unchanged. The output half now
says there are two shapes: planned when the caller cannot supply device memory,
which is every Python caller today, and unplanned when it can, which today
means a C++ caller handing the runtime a device tensor.

Test plan: read against the example exporters in the repository, which use
unplanned inputs and planned outputs with both copy skips.
Copilot AI lite review requested due to automatic review settings September 24, 2026 01:39
@pytorch-bot

pytorch-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23102

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit fc37994 with merge base b253af8 (image):

NEW FAILURE - The following job has failed:

  • Cadence Build & Test / Resolve CI docker image / resolve (gh)
    ##[error]Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@shoumikhin
shoumikhin merged commit 0f2ae90 into pytorch:main Sep 24, 2026
220 of 228 checks passed
@nil-is-all nil-is-all added module: doc Issues related to documentation, both in docs/ and inlined in code module: cuda Issues related to the AOTI CUDA backend labels Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: cuda Issues related to the AOTI CUDA backend module: doc Issues related to documentation, both in docs/ and inlined in code release notes: docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CUDA docs: the device-resident recipe uses unplanned graph outputs, which a Python caller cannot supply

4 participants